<?php
require_once 'Zend/View/Helper/Abstract.php';

/**
 * The HTML Namespace helper allows us to add and manipulate namespaces
 * defined within the root HTML tag of the XHTML DOM.
 * 
 * @author Michael Krotscheck
 */
class Core_View_Helper_HtmlNamespace
	extends Zend_View_Helper_Abstract
{
    /**
     * Registry key for placeholder
     * @var string
     */
    protected $_regKey = 'Core_View_Helper_HtmlNamespace';

    /**
     * Private namespace cache
     * 
     * @var array
     */
    protected $namespace = array();
	
    /**
     * Default Namespace Cache
     * 
     * @var string
     */
   	protected $default = 'http://www.w3.org/1999/xhtml';
   	
    /**
     * Retrieve placeholder for title element and optionally set state
     *
     * @param  string $title
     * @param  string $setType
     * @param  string $separator
     * @return Zend_View_Helper_HeadTitle
     */
    public function htmlNamespace()
    {
    	return $this;
    }

    /**
     * Sets the default namespace.
     *
     * @param  string $space
     */
    public function setDefaultNamespace( $space )
    {
    	$this->default = $space;
    }
    
    /**
     * Adds a namespace.
     *
     * @param  string $name
     * @param  string $space
     */
    public function addNamespace( $name, $space)
    {
    	$this->namespace[$name] = $space;
    }

    /**
     * Removes a namespace.
     *
     * @param  string|null $indent
     * @param  string|null $locale
     */
    public function removeNamespace( $name, $space)
    {
    	unset ( $this->namespace[$name] );
    }

    /**
     * Object toString method
     *
     * @return string
     */
    public function __toString( )
    {
    	$exportString = "xmlns=\"$this->default\"";
    	foreach ( $this->namespace as $key => $value )
    	{
    		$exportString .= " xmlns:$key=\"$value\"";
    	}
    	return $exportString;
    }
}